package com.funcourse.demo.api.restful.advices;

import com.funcourse.demo.api.restful.io.response.ApiResponse;
import com.funcourse.demo.api.restful.io.response.error.CommonUsedError;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class MyControllerAdvice {

  @ResponseBody
  @ExceptionHandler(value = Throwable.class)
  ApiResponse intercptdThrowable(Throwable throwable){
    log.error(throwable.getMessage(),throwable);
    return new ApiResponse(CommonUsedError.SERVER_ERROR,throwable.getMessage());
  }

}
